#!/bin/bash
#==============================================================================
# Copyright 2014 zod.yslin
# Author: zod.yslin
# Email:
# File Name: lsof.sh
# Description:
#   A frequent problem in network programming (and non-network programming for
#   that matter) is determining which process has a file or socket open.
#
#   Some UNIX systems have the fstat utility to do this, but it is not
#   available on all systems. Fortunately, Victor Abell’s public domain lsof
#   program is available for a wide variety of UNIX systems.
# Edit History:
#   2014-12-30    File created.
#==============================================================================
# Check some process is listening on port X
netstat -a --inet
netstat -a --protocol=inet
# If X = 6000, check its stat
lsof -i TCP:6000

# Dropbox port
lsof -i UDP:17500

# Use browser to open ftp://ftp.edu.tw, 
# then check which browser open this foreign address
lsof -i @ftp.edu.tw

# list all files user root open
lsof -u root
